package {{packageName}}.core.{{entity.module}}.mapper;

import java.util.*;
import org.apache.ibatis.annotations.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import {{packageName}}.core.{{entity.module}}.domain.{{entity.domainClassName}};
import {{packageName}}.core.{{entity.module}}.filter.{{entity.codeName}}SearchContext;
{{#entity.enableEntityCache}}
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
{{/entity.enableEntityCache}}
import java.io.Serializable;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.alibaba.fastjson.JSONObject;

/**
 * {{entity.logicName}}Mapper[{{entity.codeName}}]
 *
 * @author generator
 */
{{#entity.dsName}}
@DS("{{entity.dsName}}")
{{/entity.dsName}}
public interface {{entity.codeName}}Mapper extends BaseMapper<{{entity.domainClassName}}> {

    {{#entity.sqlMethods}}
        {{#if dataSet}}
    /**
     * 数据集合{{codeName}}分页查询
     * 
     * @param page
     * @param context
     * @param wrapper
     * @return
     */
    Page<{{#if dataSet.enableGroup}}Map{{else}}{{entity.domainClassName}}{{/if}}> search{{pascalCase codeName}}(IPage<{{entity.domainClassName}}> page, @Param("ctx") {{entity.codeName}}SearchContext context, @Param("ew") Wrapper<{{entity.domainClassName}}> wrapper);
    
    /**
     * 数据集合{{codeName}}查询
     * 
     * @param context
     * @param wrapper
     * @return
     */
    List<{{#if dataSet.enableGroup}}Map{{else}}{{entity.domainClassName}}{{/if}}> list{{pascalCase codeName}}(@Param("ctx") {{entity.codeName}}SearchContext context, @Param("ew") Wrapper<{{entity.domainClassName}}> wrapper);

        {{else if reference}}
            {{#if (eq type 'find')}}
    /**
    * 根据{{camelCase fkField.codeName}}查询
    *
    * @param {{camelCase fkField.codeName}}s
    * @return
    */
    List<{{entity.domainClassName}}> findBy{{pascalCase fkField.codeName}}(@Param("{{camelCase fkField.codeName}}s") List<{{fkField.type.java}}> {{camelCase fkField.codeName}}s);

            {{/if}}
        {{/if}}
    {{/entity.sqlMethods}}
    /**
     * 主键查询
     *
     * @param {{camelCase entity.keyField.codeName}}
     * @return
     */
    @Override
    {{#entity.enableEntityCache}}
    @Cacheable(value = "{{lowerCase entity.codeName}}", key = "'row:'+#p0")
    {{/entity.enableEntityCache}}
    {{entity.domainClassName}} selectById(Serializable id);

    /**
     * 数据对象查询
     *
     * @param entity
     * @return
     */
    {{#entity.enableEntityCache}}
    @Cacheable(value = "{{lowerCase entity.codeName}}", key = "'row:'+#p0.{{camelCase entity.keyField.codeName}}")
    {{/entity.enableEntityCache}}
    {{entity.domainClassName}} selectEntity({{entity.domainClassName}} entity);

    /**
     * 数据对象集合查询
     *
     * @param list
     * @return
     */
    List<{{entity.domainClassName}}> selectEntities(@Param("list") List<{{entity.domainClassName}}> list);

    /**
     * 自定义查询SQL
     *
     * @param sql
     * @param param
     * @return
     */
    @Select("${sql}")
    List<JSONObject> selectBySQL(@Param("sql") String sql, @Param("et")Map<String,Object> param);

    /**
     * 自定义更新SQL
     *
     * @param sql
     * @param param
     * @return
     */
    @Update("${sql}")
    boolean updateBySQL(@Param("sql") String sql, @Param("et")Map<String,Object> param);

    /**
     * 自定义插入SQL
     *
     * @param sql
     * @param param
     * @return
     */
    @Insert("${sql}")
    boolean insertBySQL(@Param("sql") String sql, @Param("et")Map<String,Object> param);

    /**
     * 自定义删除SQL
     *
     * @param sql
     * @param param
     * @return
     */
    @Delete("${sql}")
    boolean deleteBySQL(@Param("sql") String sql, @Param("et")Map<String,Object> param);
}